#include <my_header.h>
// 写端 写入文件名 长度 内容 读端创建文件
/* Usage: ./5_send_write */
int main(int argc, char *argv[]){                                  
    int pipe_fd = open("shared.pipe", O_WRONLY);
    ERROR_CHECK(pipe_fd, -1, "open write");

    char* name = "test1.txt";
    int file_length = 10;
    char* str = "helloworld";

    // 获取文件名的长度
    int name_length = strlen(name);
    write(pipe_fd, &name_length, sizeof(int));
    write(pipe_fd, name, name_length);
    
    write(pipe_fd, &file_length, sizeof(int));

    // 获取文件内容的长度
    int str_length = strlen(str);
    write(pipe_fd, &str_length, sizeof(int));
    write(pipe_fd, str, str_length);
    
    // 关闭文件描述符
    close(pipe_fd);
    return 0;
}


